programming4us
           
 
 
Programming

Coding JavaScript for Mobile Browsers (part 5)

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/25/2010 3:27:44 PM
2.6. History and URL management

JavaScript has a few standard mechanisms for browser history management: the location and history objects. The location object has several properties regarding the address, like href for the whole URL and hash for the anchor part of the URL, if present (the # and everything to the right of it). Changing the location.href property will redirect the browser to another page, on compatible devices. It has two useful methods: reload(), which refreshes the same page, and replace(url), which sends the user to another page without creating a new history entry.


Warning:

Remember to use JavaScript as little as possible to reduce battery consumption (one of the main problems today in the mobile environment).


The history object has a few not-very-useful properties and three methods: back(), go(number), and forward(). The back method is the most commonly used, for emulating a back button:

<!-- As a button -->
<input type="button" onclick="history.back()" value="Back" />
<!-- As a link -->
<a href="javascript:history.back()">Back</a>

Remember that we are designing for mobile browsers, and sometimes the users will be browsing in full-screen mode without any browser buttons in sight. A link or button for going back will be more useful here than in desktop websites.

Table 8 shows what happens when we try to manage the history and location using JavaScript in mobile devices.

Table 8. Redirection compatibility table
Browser/platformhref, replace, reload, and history.back support
SafariYes
Android browserYes
Symbian/S60Yes
Nokia Series 40Yes
webOSYes
BlackBerryYes
NetFrontYes
Internet ExplorerYes
Motorola Internet BrowserYes
Opera MobileYes
Opera MiniYes, reload causes a new history entry

2.7. Manipulating windows

One of the most popular (and annoying) features of JavaScript is the usage of window.open for opening the classic pop-up windows. For mobile browsers, the usage of this technique is not ideal, for many reasons. Many browsers can’t open multiple windows (although Figure 3 shows one that can in action), and we cannot define any attributes for the pop-ups; they will just be full-sized, like the main window. Communication between the opener and the pop-up also often does not work well. Finally, closing pop-ups can be problematic on browsers that treat the new window as a normal page and not a pop-up, because window.close only works on pop-ups.

Figure 3. The Android browser is one of the few capable of opening pop-ups with a subwindow design.


So, if you can, avoid using pop-ups. If you really need one for some reason, open the window after an onclick event (avoid opening windows in the onload event or inside a timer callback) and remember that some mid- and low-end devices will not show your window.


Note:

A better alternative is to use a link with target="_blank". This will have the same result in mobile devices as a window.open call, and it will work on every browser. If the browser doesn’t support multiple windows, it will just replace the current one.


Table 9 reports on how the different browsers handle window.open.

Table 9. window.open compatibility table
Browser/platformwindow.open behavior
SafariSame as _blank. window.close works, but the user will be redirected to the windows list after, not back to the original window.
Android browserYes, pop-up behavior and design. Your defined size will not be used.
Symbian/S60Open in new window.
Nokia Series 40Open in same window.
webOSOpen a new card. window.close does not work.
BlackBerryOpen in same window. Before 4.6, the user is asked if he wants to open it.
NetFrontOpen in same window. window.close does not work.
Internet ExplorerOpen in same window. window.close does not work.
Motorola Internet BrowserOpen in same window.
Opera MobileOpen in same window.
Opera MiniOpen in same window.
Other -----------------
- Programming the Mobile Web : JavaScript Mobile - Supported Technologies
- Security in Cloud Computing (part 4) - Audit and Compliance
- Security in Cloud Computing (part 3)
- Security in Cloud Computing (part 2) - Identity and Access Management
- Security in Cloud Computing (part 1) - Data Security and Storage
- Cloud Security and Privacy : Analyst Predictions
- CSS for Mobile Browsers : WebKit Extensions (part 2) - Border Image
- CSS for Mobile Browsers : WebKit Extensions (part 1) - Text Stroke and Fill
- jQuery 1.3 : Working with numeric form data (part 9) - The finished code
- jQuery 1.3 : Working with numeric form data (part 8) - Editing shipping information
- jQuery 1.3 : Working with numeric form data (part 7) - Deleting items
- jQuery 1.3 : Working with numeric form data (part 6) - Finishing touches
- jQuery 1.3 : Working with numeric form data (part 5)
- jQuery 1.3 : Working with numeric form data (part 4) - Dealing with decimal places
- jQuery 1.3 : Working with numeric form data (part 3) - Parsing and formatting currency
- jQuery 1.3 : Working with numeric form data (part 2)
- jQuery 1.3 : Working with numeric form data (part 1) - Shopping cart table structure
- The Art of SEO : Controlling Content with Cookies and Session IDs
- iPad SDK : New Graphics Functionality - We Are All Tool Users (part 5) - The Freehand Tool
- iPad SDK : New Graphics Functionality - We Are All Tool Users (part 4) - The Ellipse and Rectangle Tools
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us